package com.atguigu.listener;


import jakarta.servlet.ServletContextAttributeEvent;
import jakarta.servlet.ServletContextAttributeListener;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import jakarta.servlet.annotation.WebListener;

@WebListener
public class MyAppListener implements ServletContextListener, ServletContextAttributeListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("MyAppListener " + sce.getServletContext().hashCode() + " contextInitialized");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("MyAppListener " + sce.getServletContext().hashCode() + " contextDestroyed");
    }

    @Override
    public void attributeAdded(ServletContextAttributeEvent scae) {
        System.out.println("MyAppListener " + scae.getServletContext().hashCode()+":"+scae.getName() + " attributeAdded:"+scae.getValue());
    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent scae) {
        System.out.println("MyApplistener " + scae.getServletContext().hashCode()+":"+scae.getName() + " attributeRemoved");
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent scae) {
        System.out.println("MyAppListener " + scae.getServletContext().hashCode()+":"+scae.getName() +
                " attributeReplaced:"+scae.getValue()+
                " to:"+scae.getServletContext().getAttribute(scae.getName()));
    }
}
